package com.xbongbong.paas.pojo;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.saas.domain.entity.MarketingSettingDistributorEntity;
import com.xbongbong.saas.enums.MarketingManagementSettingEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author youli.chen
 * @version v1.0
 * @description: TODO
 * @date 2019/4/2 19:04
 * @since v1.0
 */
@Setter
@Getter
@ToString
public class MarketingSettingValuePojo implements Serializable {

    private static final long serialVersionUID = -414293231977092093L;

    /**
     * 优惠券是否支持退回
     * 0不退回，1退回
     */
    private Integer back;
    /**
     * 是否开启优惠券使用比例设置
     * 0不支持，1支持
     */
    private Integer couponRatio;
    /**
     * 是否支持0元支付
     * 0不支持，1支持
     */
    private Integer freeCharge;
    /**
     * 营销计算规则设置开启
     */
    private Integer status;
    /**
     * 多张同类型优惠券叠加使用
     * 0不支持，1支持
     */
    private Integer syncSameCoupon;
    /**
     * 促销和优惠券同时叠加
     * 0不支持，1支持
     */
    private Integer syncCouponPromotion;
    /**
     * 具体经销商和折扣
     */
    private List<MarketingSettingDistributorEntity> distributorList;


    public MarketingSettingValuePojo() {
    }

    public MarketingSettingValuePojo(Integer couponRatio, Integer freeCharge) {
        this.couponRatio = couponRatio;
        this.freeCharge = freeCharge;
    }

    public MarketingSettingValuePojo(Integer status,Integer syncSameCoupon, Integer syncCouponPromotion) {
        this.status = status;
        this.syncSameCoupon = syncSameCoupon;
        this.syncCouponPromotion = syncCouponPromotion;
    }

    public static MarketingSettingValuePojo defaultCouponSetting = new MarketingSettingValuePojo(1,0);

    static {
        List<MarketingSettingDistributorEntity> distributorEntityList = new ArrayList<>();
        MarketingSettingDistributorEntity distributorEntity = new MarketingSettingDistributorEntity();
        distributorEntity.setDiscount(PaasConstant.couponRatio);
        distributorEntity.setIsDefault(1);
        distributorEntityList.add(distributorEntity);
        defaultCouponSetting.setDistributorList(distributorEntityList);
        defaultCouponSetting.setBack(0);
    }

    public static MarketingSettingValuePojo defaultMarketingSetting = new MarketingSettingValuePojo(1,0,1);

    public static MarketingSettingValuePojo getByType(Integer code){
        if (Objects.equals(code, MarketingManagementSettingEnum.COUPON_USAGE_SETTING.getCode())) {
            return defaultCouponSetting;
        }else if (Objects.equals(code, MarketingManagementSettingEnum.MARKETING_CALCULATION_RULE_SETTING.getCode())){
            return defaultMarketingSetting;
        }
        return new MarketingSettingValuePojo();
    }
}
